package com.haina.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haina.shop.domain.Category;
import com.haina.shop.domain.Prod;
import com.haina.shop.mapper.ProdMapper;
import com.haina.shop.service.CategoryService;
import com.haina.shop.mapper.CategoryMapper;
import com.haina.shop.vo.CategoryVo;
import com.haina.shop.vo.PageVo;
import com.haina.shop.vo.ProductVO;
import org.apache.commons.codec.language.Caverphone1;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
* @author 48077
* @description 针对表【tz_category(产品类目)】的数据库操作Service实现
* @createDate 2024-07-31 18:34:29
*/
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category>
    implements CategoryService{

    @Resource
    private ProdMapper prodMapper;

    @Resource
    private CategoryMapper categoryMapper;

    public PageVo pageSelect(long categoryId, PageVo pageVo){

        long total=prodMapper.selectCount1(categoryId);
        pageVo.setTotal(total);
        pageVo.setPages(pageVo.getCurrent());

        List<ProductVO> list=new ArrayList<>();
        List<Prod> prods = prodMapper.selectByCategory(categoryId);
        System.out.println(prods.size());
        for (Prod prod:prods){
            ProductVO productVO=new ProductVO();
            productVO.setBrief(prod.getBrief());
            productVO.setCategoryId(categoryId);
            productVO.setContent(prod.getContent());
            productVO.setImgs(prod.getImgs());
            productVO.setOriPrice(prod.getOriPrice());
            productVO.setPic(prod.getPic());
            productVO.setPrice(prod.getPrice());
            productVO.setProdId(prod.getProdId());
            productVO.setProdName(prod.getProdName());
            productVO.setSkuList(null);
            productVO.setTotalStocks(prod.getTotalStocks());
            productVO.setTransport(null);
            list.add(productVO);
        }
        pageVo.setRecords(list);
        return pageVo;
    }
    public  List<CategoryVo> category(long parentId){
        List<Category> categories = categoryMapper.selectByParentId(parentId);
        List <CategoryVo> list=new ArrayList<>();
        for (Category category: categories){
            CategoryVo categoryVo = new CategoryVo();
            categoryVo.setParentId(parentId);
            categoryVo.setCategoryId(category.getCategoryId());
            categoryVo.setCategoryName(category.getCategoryName());
            categoryVo.setPic(category.getPic());
            list.add(categoryVo);
        }
        return list;
    }

}




